package com.wpj.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.plugins.Page;
import com.wpj.common.entity.ResultEntity;
import com.wpj.entity.User;
import com.wpj.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class UserController {

    @Reference
    private IUserService userService;

    @RequestMapping("/getUserPage")
    public String getUserPage(Page<User> page, ModelMap map){
        page = userService.getDubboPage(page);
        map.put("url", "user/getUserPage");
        map.put("page",page);
        return "user/userList";
    }

    @RequestMapping("/addUser")
    @ResponseBody
    public ResultEntity addUser(User user){
        int insert = userService.insert(user);
        if (insert > 0) {
            return ResultEntity.SUCCESS();
        } else{
            return ResultEntity.FALL();
        }
    }

    @RequestMapping(value = "/getUserById/{id}")
    public String getUserById(@PathVariable Integer id,ModelMap map){
        User user = userService.selectById(id);
        map.put("user",user);
        return "user/updateUser";
    }

}
